import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

let store = new Vuex.Store({
  // 三大将
  state: {
    userInfo: {},//用户信息
    apiPreviousInfo: {},  // 上一次接口保存信息
    choicesInfo: {},  // 项目所有的CHOICES
  },
  // 修改state的唯一方法 是提交mutations
  mutations: {
    getUserInfo(state, user) {
      state.userInfo = user;
    },
    getApiPreviousInfo(state, data) {
      state.apiPreviousInfo = data;
    },
    getChoicesInfo(state, data) {
      state.choicesInfo = data;
    },
  },
  actions: {
    getUserInfo({commit}, user) {
      commit('getUserInfo', user);
    },
    getChoicesInfo({commit}, data) {
      commit('getChoicesInfo', data);
    },
    getApiPreviousInfo({commit}, data) {
      commit('getApiPreviousInfo', data);
    },

  }
});
export default store;
